package com.css.fxfzypg.modules.earthquakedisasterloss.service.impl;

import com.css.fxfzypg.modules.baseData.entity.PbeEntity;
import com.css.fxfzypg.modules.earthquakedisasterloss.entity.PlantPbe;
import com.css.fxfzypg.modules.earthquakedisasterloss.repository.YpgResultPbeRepository;
import com.css.fxfzypg.modules.earthquakedisasterloss.service.YpgResultPbeService;
import com.css.fxfzypg.modules.earthquakedisasterloss.vo.SeismicInfluencefliedVO;
import com.css.fxfzypg.util.UUIDGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2022/11/4 9:28
 */
@Service
public class YpgResultPbeServiceImpl implements YpgResultPbeService {
    @Resource
    YpgResultPbeRepository ypgResultPbeRepository;

    @Override
    public void savePlantPbe(String taskId, String pbeId,SeismicInfluencefliedVO seismicInfluencefliedVO,BigDecimal plantPerson){
        PlantPbe plantPbe=new PlantPbe();
        plantPbe.setId(UUIDGenerator.getUUID());
        plantPbe.setTaskId(taskId);
        plantPbe.setPdeId(pbeId);
        plantPbe.setEarthquakeId(seismicInfluencefliedVO.getEarthquakeId());
        plantPbe.setInfluencefliedId(seismicInfluencefliedVO.getInfluencefliedId());
        plantPbe.setMagnitude(seismicInfluencefliedVO.getEarthquakeLevel());
        plantPbe.setAngle(seismicInfluencefliedVO.getAngle());
        plantPbe.setSort(String.valueOf(seismicInfluencefliedVO.getFaultNum()));
        plantPbe.setLongitude(seismicInfluencefliedVO.getLongitude().toString());
        plantPbe.setLatitude(seismicInfluencefliedVO.getLatitude().toString());
        plantPbe.setDzIntensity(seismicInfluencefliedVO.getDzIntensity());
        plantPbe.setPlantPerson(plantPerson.setScale(0, BigDecimal.ROUND_UP));
        ypgResultPbeRepository.savePlantPbe(plantPbe);
    }

    @Override
    public PlantPbe savePlantPbe1(String taskId, String pbeId, String geomText, int i, BigDecimal plantPerson) {
        PlantPbe plantPbe=new PlantPbe();
        plantPbe.setId(UUIDGenerator.getUUID());
        plantPbe.setTaskId(taskId);
        plantPbe.setPdeId(pbeId);
        plantPbe.setDzIntensity(String.valueOf(i));
        plantPbe.setPlantPerson(plantPerson.setScale(6,BigDecimal.ROUND_HALF_DOWN));
        plantPbe.setGeomText(geomText);
        ypgResultPbeRepository.savePlantPbe(plantPbe);
        return plantPbe;
    }
    @Override
    public PlantPbe getNewPlantPbe(String taskId, String pbeId, String geomText, int i, BigDecimal plantPerson) {
        PlantPbe plantPbe=new PlantPbe();
        plantPbe.setId(UUIDGenerator.getUUID());
        plantPbe.setTaskId(taskId);
        plantPbe.setPdeId(pbeId);
        plantPbe.setDzIntensity(String.valueOf(i));
        plantPbe.setPlantPerson(plantPerson.setScale(6,BigDecimal.ROUND_HALF_DOWN));
        plantPbe.setGeomText(geomText);
        return plantPbe;
    }

    @Override
    public void createResultPbeFqRel(String taskId) {
        ypgResultPbeRepository.createResultPbeFqRel(taskId);
    }


    @Override
    public List<PlantPbe> getByTaskId(String taskId) {
        return ypgResultPbeRepository.getByTaskId(taskId);
    }

    @Override
    public int delPlantPbe(String taskId) {
        return ypgResultPbeRepository.delPlantPbe(taskId);
    }

    @Override
    public List<PbeEntity> getPbeByTaskId(String taskId) {
        return ypgResultPbeRepository.getPbeByTaskId(taskId);
    }

    @Override
    public List<PlantPbe> getPbeByDzIntensity(String taskId, String dzIntensity) {
        return ypgResultPbeRepository.getPbeByDzIntensity(taskId,dzIntensity);
    }

    @Override
    public List<Map<String, Object>> getPlantPbeByTaskId(String taskId,String range) {
        return ypgResultPbeRepository.getPlantPbeByTaskId(taskId,range);
    }

    @Override
    public int savePlantPbeList(List<PlantPbe> plantPbeList) {
        int size = ypgResultPbeRepository.savePlantPbeList(plantPbeList);
        return size;
    }
}
